package net.simflow.swf.analyzer.gui.ginfo.generator;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map.Entry;

import net.simflow.swf.analyzer.data.StringConstant;
import net.simflow.swf.analyzer.data.TupleStrInt;

public abstract class AbstractGenerator {

	public ArrayList<TupleStrInt> generate(Object stats,
			LinkedHashMap<String, Boolean> config) {
		if (stats == null || config == null) {
			return null;
		}

		ArrayList<TupleStrInt> info = new ArrayList<TupleStrInt>();
		for (Entry<String, Boolean> en : config.entrySet()) {
			if (!en.getValue()) {
				continue;
			}

			ArrayList<TupleStrInt> tmp = null;
			String style = en.getKey();
			tmp = getInfo(style, stats);

			if (tmp != null && tmp.size() > 0) {
				info.addAll(tmp);
			}
		}
		if (info.size() > 0) {
			info.add(0, new TupleStrInt(getTitle(stats),
					StringConstant.PKG_TITLE));
		}

		return info;
	}

	abstract public LinkedHashMap<String, Boolean> getDefaultConfig();

	abstract protected String getTitle(Object stats);

	abstract protected ArrayList<TupleStrInt> getInfo(String style, Object stats);
}
